package com.foreknow.demo2;

/**
 * 多态的应用
 */
public class TestSync {

    public Pet m1(Pet[] pets) {
        return pets[0];
    }

    public static void main(String[] args) {
        Pet[] pets = new Pet[2];
        Dog dog = new Dog();
        dog.setName("小黄");
        Penguin penguin = new Penguin();
        penguin.setName("QQ");
        //将对象保存到Pet类型的数组中
        pets[0] = dog;
        pets[1] = penguin;
        //调用TestSync类中的m1方法
        TestSync sync = new TestSync();
        Pet pet = sync.m1(pets);
        pet.getName();
    }
}
